package cn.tedu.baking.controller;

import cn.tedu.baking.pojo.dto.CommentSaveDTO;
import cn.tedu.baking.pojo.vo.CommentVO;
import cn.tedu.baking.response.common.JsonResult;
import cn.tedu.baking.service.ICommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author：毕龙
 * Date: 2024/8/17 15:49
 */
@RestController
@RequestMapping("/v1/comments/")
@Slf4j
public class CommentController {

    @Autowired
    private ICommentService iCommentService;

    public CommentController(){
        log.debug("创建CommentController对象");
    }

    @GetMapping("/{id}")
    public JsonResult getCommentsByContentId(@PathVariable Integer id){
        log.debug("获取数据内容：{}",id);
        List<CommentVO> vo = iCommentService.getCommentsByContentId(id);
        return JsonResult.ok(vo);
    }
    @PostMapping("/save")
    public JsonResult saveCommentsByContentId(CommentSaveDTO commentSaveDTO){
        log.debug("获取数据内容：{}",commentSaveDTO);
        iCommentService.saveCommentsByContentId( commentSaveDTO);
        return JsonResult.ok();
    }

}
